package com.itlong.cloud.rabbitmq.config;

import com.itlong.cloud.constants.RabbitMQConstant;
import com.itlong.cloud.utils.rabbitMQ.BaseConfig;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * <desc>
 *      短信通知开发人员异常信息队列配置.
 * </desc>
 *
 * @createDate 2020/11/16
 */
@Configuration
public class RabbitConfig extends BaseConfig {

    // 声明交换器
    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange(RabbitMQConstant.RABBITMQ_NOTIFY_DEVLOPS_EXCPTMSG_EXCHANGE);
    }

    // 短信通知开发人员异常信息队列
    @Bean
    public Queue notifyDevlopsExcptMsgQueue() {
        Map<String, Object> map = new HashMap<>();
        map.put("x-message-ttl", RabbitMQConstant.QUEUE_TTL);
        map.put("x-dead-letter-exchange", RabbitMQConstant.DEAD_LETTER_EXCHANGE);
        map.put("x-dead-letter-routing-key", RabbitMQConstant.MAIL_QUEUE_FAIL);
        Queue queue = new Queue(RabbitMQConstant.RABBITMQ_NOTIFY_DEVLOPS_EXCPTMSG_QUEUE,true, false, false, map);
        return queue;
    }

    // 绑定短信通知开发人员异常信息队列路由key
    @Bean
    Binding deleteUnitBinding() {
        return BindingBuilder.bind(notifyDevlopsExcptMsgQueue()).to(topicExchange()).with(RabbitMQConstant.RABBITMQ_NOTIFY_DEVLOPS_EXCPTMSG_KEY);
    }

}
